package com.ct.controller.shipping;

import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanYuanFenZuSavePO;
import com.ct.application.shipping.model.vo.ChuanYuanFenZuVO;
import com.ct.application.shipping.service.ChuanYuanFenZuService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 船舶分组配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船舶分组",path="/api/v1/chuanyuanfenzu",code = "A1000",sorted = 8)
public class ChuanYuanFenzuController extends BaseController {

    @Resource
    private ChuanYuanFenZuService chuanYuanFenZuService;

    /**
     * 查询船舶分组列表
     * @return
     */
    @PostMapping("/chuanyuanfenzu/list")
    @PermissionApi(title = "查询船舶分组列表",path="/api/v1/chuanyuanfenzu/list",code = "A1001",sorted = 1)
    public List<ChuanYuanFenZuVO> findChuanYuanFenZus() {
        return chuanYuanFenZuService.findChuanYuanFenZu();
    }

    /**
     * 查询船舶分组列表
     * @return
     */
    @PostMapping("/chuanyuanfenzu/listbiao")
    @PermissionApi(title = "查询船舶分组列表",path="/api/v1/chuanyuanfenzu/listbiao",code = "A1007",sorted = 7)
    public List<ChuanYuanFenZuVO> findChuanYuanFenZuList() {
        return chuanYuanFenZuService.findChuanYuanFenZuList();
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanyuanfenzu/saveupdate")
    @ApiLog("船舶分组保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船舶分组保存和更新",path="/api/v1/chuanyuanfenzu/saveupdate",code = "A1003",sorted = 3)
    public Boolean saveUpdateChuanYuanFenZu(@Validated @RequestBody ChuanYuanFenZuSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanYuanFenZuService.updateChuanYuanFenZu(savePO);
        }else {
            return chuanYuanFenZuService.saveChuanYuanFenZu(savePO);
        }
    }

    /**
     * 根据id查询船舶分组
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuanfenzu/get/{id}")
    @PermissionApi(title = "根据id查询船舶分组",path="/api/v1/chuanyuanfenzu/get/{id}",code = "A1004",sorted = 4)
    public ChuanYuanFenZuVO getChuanYuanFenZuById(@PathVariable("id") Long id) {
        return chuanYuanFenZuService.getChuanYuanFenZu(id);
    }


    /**
     * 根据id删除船舶分组
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuanfenzu/del/{id}")
    @ApiLog("根据id删除船舶分组")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除船舶分组",path="/api/v1/chuanyuanfenzu/del/{id}",code = "A1005",sorted = 5)
    public Boolean delChuanYuanFenZuById(@PathVariable("id") Long id) {
        return chuanYuanFenZuService.delChuanYuanFenZu(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanyuanfenzu/update/status")
    @ApiLog("船舶分组修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船舶分组修改状态",path="/api/v1/chuanyuanfenzu/update/status",code = "A1006",sorted = 6)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanYuanFenZuService.updateStatus(statusRequest);
    }
}
